home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Franz PD / Franz PD Disk #009 (19xx)(Amiga User Group Deutschland e.V.).zip / Franz PD Disk #009 (19xx)(Amiga User Group Deutschland e.V.).adf / ScreenShift / SS.c < prev    next >
C/C++ Source or Header  |  1986-10-22  |  5KB  |  190 lines

  1. /* ScreenShift 1.0
  2.  * Anson Mah
  3.  * June 4, 1987
  4.  * Completely in the Public Domain
  5.  * Written for Lattice C
  6.  */
  7.  
  8. /* #define DEBUG */
  9.  
  10. #include <exec/types.h>
  11. #include <exec/memory.h>
  12. #include <intuition/intuition.h>
  13.  
  14. #ifdef DEBUG
  15. #include <stdio.h>
  16. #endif
  17.  
  18. #define PROPGADWIDTH    200    /* gadget proportions */
  19. #define PROPGADHEIGHT    50
  20. #define XJUMP    512        /* add to Vert/HorizPot when */
  21. #define YJUMP    1024        /*   moving with cursor keys */
  22. #define UP    0x4c        /* cursor key RAWKEYS */
  23. #define DOWN    0x4d        /* also defined in intuition.h, */
  24. #define LEFT    0x4f        /*   but included for clarity */
  25. #define RIGHT    0x4e
  26. #define CR    0x44        /* RETURN key */
  27.  
  28. extern UWORD xoffset(), yoffset();    /* the math.s routines */
  29. extern BYTE xpot(), ypot();
  30.  
  31. struct IntuitionBase *IntuitionBase;
  32. struct GfxBase *GfxBase = NULL;
  33. struct Preferences *pref = NULL;
  34. struct Window *pwin = NULL;
  35.  
  36. UWORD pimagedata[] = {
  37.     0x0000,0x0000,0x0000,    /* bit plane 0 */
  38.     0x7FFF,0xFFFF,0xFE00,
  39.     0x7FFE,0x3F1F,0xFE00,
  40.     0x7FF9,0x9CCF,0xFE00,
  41.     0x7FF9,0xFCFF,0xFE00,
  42.     0x7FFE,0x7F3F,0xFE00,
  43.     0x7FE6,0x733F,0xFE00,
  44.     0x7FF0,0xF87F,0xFE00,
  45.     0x7FFF,0xFFFF,0xFE00,
  46.     0x0000,0x0000,0x0000,
  47.     0xFFFF,0xFFFF,0xFF00,    /* bit plane 1 */
  48.     0xFFFF,0xFFFF,0xFF00,
  49.     0xFFFF,0xFFFF,0xFF00,
  50.     0xFFFF,0xFFFF,0xFF00,
  51.     0xFFFF,0xFFFF,0xFF00,
  52.     0xFFFF,0xFFFF,0xFF00,
  53.     0xFFFF,0xFFFF,0xFF00,
  54.     0xFFFF,0xFFFF,0xFF00,
  55.     0xFFFF,0xFFFF,0xFF00,
  56.     0xFFFF,0xFFFF,0xFF00
  57. };
  58.  
  59. struct Image pimage = { 0, 0, 40, 10, 2, &pimagedata[0], 0x03, 0x00, NULL };
  60.  
  61. struct PropInfo pinfo = { FREEVERT | FREEHORIZ, 0,0, MAXBODY/5,MAXBODY/5, 0,0,0,0,0 };
  62.  
  63. struct Gadget pgadget = {
  64.     NULL, 0, 10, PROPGADWIDTH, PROPGADHEIGHT, GADGIMAGE, FOLLOWMOUSE,
  65.     PROPGADGET, (APTR)&pimage, NULL, NULL, 0, (APTR)&pinfo,
  66.     0, NULL
  67. };
  68.  
  69. struct NewWindow pwindef = {
  70.     220, 70,
  71.     PROPGADWIDTH, PROPGADHEIGHT + 10,
  72.     0, 3,
  73.     CLOSEWINDOW | MOUSEMOVE | RAWKEY,
  74.     WINDOWDEPTH | WINDOWCLOSE | WINDOWDRAG | ACTIVATE | SMART_REFRESH | RMBTRAP,
  75.     &pgadget,
  76.     NULL,
  77.     "ScreenShift",
  78.     NULL, NULL,
  79.     0,0, 0,0,
  80.     WBENCHSCREEN
  81. };
  82.  
  83. void closestuff()
  84. {
  85.     if (pref)        FreeMem(pref, sizeof(struct Preferences));
  86.     if (pwin)        CloseWindow(pwin);
  87.     if (GfxBase)        CloseLibrary(GfxBase);
  88.     if (IntuitionBase)    CloseLibrary(IntuitionBase);
  89. #ifdef DEBUG
  90.     exit(0);
  91. #else
  92.     XCEXIT(0);
  93. #endif
  94. }
  95.  
  96. void openstuff()
  97. {
  98.     IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 33);
  99.     GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 33);
  100.  
  101.     if (IntuitionBase == NULL || GfxBase == NULL)
  102.         closestuff();
  103.  
  104.     if (!(pref = (struct Preferences *)AllocMem(sizeof(struct Preferences),
  105.         MEMF_PUBLIC)))
  106.         closestuff();
  107.  
  108.     /* get current preference setting */
  109.     (void)GetPrefs(pref, sizeof(struct Preferences));
  110.     /* set up prop gadget with current View settings */
  111.     pinfo.HorizPot = xoffset(pref->ViewXOffset);
  112.     pinfo.VertPot = yoffset(pref->ViewYOffset);
  113. #ifdef DEBUG
  114.     printf("x: %d  y: %d\n", pref->ViewXOffset, pref->ViewYOffset);
  115.     printf("x: %d  y: %d\n", pinfo.HorizPot, pinfo.VertPot);
  116. #endif
  117.     if (!(pwin = (struct Window *)OpenWindow(&pwindef)))
  118.         closestuff();    /* couldn't open window */
  119. }
  120.  
  121. #ifdef DEBUG
  122. void main()
  123. #else
  124. void _main()
  125. #endif
  126. {
  127.     struct IntuiMessage *msg;
  128.     ULONG class, code;
  129.     BYTE xoffset, yoffset;
  130.  
  131.     openstuff();
  132.  
  133.     for (;;) {
  134.         WaitPort(pwin->UserPort);
  135.         msg = (struct IntuiMessage *)GetMsg(pwin->UserPort);
  136.         class = msg->Class;
  137.         code = msg->Code;
  138.         ReplyMsg(msg);
  139.  
  140.         switch (class) {
  141.             case CLOSEWINDOW:
  142.                 closestuff();
  143.                 break;
  144.             case RAWKEY:
  145.               switch (code) {
  146.                 case UP:
  147.                     if (pinfo.VertPot >= YJUMP)
  148.                         pinfo.VertPot -= YJUMP;
  149.                     else    pinfo.VertPot = 0;
  150.                     break;
  151.                 case DOWN:
  152.                     if (pinfo.VertPot < MAXBODY - YJUMP)
  153.                         pinfo.VertPot += YJUMP;
  154.                     else    pinfo.VertPot = MAXBODY;
  155.                     break;
  156.                 case LEFT:
  157.                     if (pinfo.HorizPot >= XJUMP)
  158.                         pinfo.HorizPot -= XJUMP;
  159.                     else    pinfo.HorizPot = 0;
  160.                     break;
  161.                 case RIGHT:
  162.                     if (pinfo.HorizPot < MAXBODY - XJUMP)
  163.                         pinfo.HorizPot += XJUMP;
  164.                     else    pinfo.HorizPot = MAXBODY;
  165.                     break;
  166.                 case CR:    /* carriage return */
  167.                     closestuff();    /* quit */
  168.                     break;
  169.               }
  170.               RefreshGadgets(&pgadget, pwin, NULL);
  171.               /* fall through */
  172.             case MOUSEMOVE:
  173.                 xoffset = xpot(pinfo.HorizPot);
  174.                 yoffset = ypot(pinfo.VertPot);
  175.                 if (pref->ViewXOffset != xoffset || pref->ViewYOffset != yoffset) {
  176.                     pref->ViewXOffset = xoffset;
  177.                     pref->ViewYOffset = yoffset;
  178.                     (void)SetPrefs(pref, sizeof(struct Preferences), FALSE);
  179. #ifdef DEBUG
  180.     printf("x: %d  y: %d\n", pref->ViewXOffset, pref->ViewYOffset);
  181.     printf("x: %d  y: %d\n", pinfo.HorizPot, pinfo.VertPot);
  182. #endif
  183.                 }
  184.                 break;
  185.         }
  186.     }
  187. }
  188.  
  189. void MemCleanup() {}    /* stub for Lattice */
  190.